﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.IO;


namespace ACNetMusic
{    
    class DataProvider
    {
        //private static string startUpPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", "");


        protected static string _connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFileName=D:\2011-2012\Advanced_Networking\ACNetMusic_ProjectSVN\Database\ACNetDatabase.mdf" + ";Integrated Security=True;User Instance=True";

        public static string ConnectionString
        {
            get { return DataProvider._connectionString; }
            set { DataProvider._connectionString = value; }
        }
        protected SqlConnection connection;
        protected SqlDataAdapter adapter;
        protected SqlCommand command;

        public void connect()
        {
            connection = new SqlConnection(ConnectionString);
            connection.Open();
        }
        public void disconnect()
        {
            connection.Close();
        }
        public IDataReader executeQuery(string sqlString)
        {
            command = new SqlCommand(sqlString, connection);
            return command.ExecuteReader();
        }

        public void executeNonQuery(string sqlString)
        {
            command = new SqlCommand(sqlString, connection);
            command.ExecuteNonQuery();
        }

        public object executeScalar(string sqlString)
        {
            command = new SqlCommand(sqlString, connection);
            return command.ExecuteScalar();
        }

        protected ArrayList ConverDataSetToArrayList(DataSet dataset)
        {
            ArrayList arr = new ArrayList();
            DataTable dt = dataset.Tables[0];
            int i, n = dt.Rows.Count;
            for (i = 0; i < n; i++ )
            {
                object obj = GetDataFromDataRow(dt, i);
                arr.Add(obj);
            }
            return arr;
        }

        protected virtual  object GetDataFromDataRow(DataTable dt, int i)
        {
            return null;
        }
    }
}
